Skip to content

fix(version): read package version at runtime instead of npm env var - #5

Merged
thaolaptrinh merged 1 commit into
mainfrom
fix/proxy-version-display
Aug 22, 2026
Merged

fix(version): read package version at runtime instead of npm env var#5
thaolaptrinh merged 1 commit into
mainfrom
fix/proxy-version-display

Conversation

@thaolaptrinh

Copy link
Copy Markdown
Owner

Problem

The startup banner and the /health endpoint reported v0.1.0 instead of the real installed version whenever the proxy was started outside an npm script — e.g. node dist/proxy.js, make start, or a globally installed binary.

Root cause

src/proxy.ts and src/server.ts read process.env.npm_package_version, which is only set by npm/pnpm run scripts. In all other run modes it is undefined, so the hardcoded "0.1.0" fallback was used.

Fix

  • Add src/version.ts: reads package.json located next to the module at runtime (via import.meta.url), so it resolves correctly in all run modes (tsx src/, node dist/, global binary). Falls back to the env var, then 0.0.0.
  • Use getProxyVersion() in the startup banner (src/proxy.ts) and /health (src/server.ts).

Testing

  • New tests/version.test.ts deletes npm_package_version to reproduce the bug and asserts the real version is returned.
  • /health test now asserts version matches package.json.
  • Full suite: 154/154 passing; tsc --noEmit clean.
  • Manually verified node dist/proxy.js prints v0.3.0 and /health returns {"status":"ok","version":"0.3.0"}.

The startup banner and /health endpoint fell back to a hardcoded "0.1.0"
whenever the proxy was run outside an npm script (node dist/proxy.js,
make start, or a globally installed binary) because
npm_package_version is only set by npm/pnpm run. Add a version module
that reads package.json next to the module at runtime, so all run
modes report the real version.
@thaolaptrinh
thaolaptrinh merged commit 87a41fb into main Aug 22, 2026
2 checks passed
@thaolaptrinh
thaolaptrinh deleted the fix/proxy-version-display branch August 22, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant